package cn.gbase.jiangsu.data.transfer;

import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.view.JspView;
import org.nutz.mvc.view.ViewWrapper;

import cn.gbase.jiangsu.data.transfer.util.SystemContext;

/**
 * 检查当前 Session，是否存user属性，存在代码正常 <br>
 * 否则，返回一个 ServerRecirectView 到对应 path 或弹出登录窗口
 */
public class CheckSession implements ActionFilter {

	private static final String timeOutMsg = "{'会话超时，请重新登录！'}";

	@Override
	public View match(ActionContext context) {
		Object supplierUser = Mvcs.getHttpSession().getAttribute(SystemContext.SUPPLIERUSER);
		Object companyUser = Mvcs.getHttpSession().getAttribute(SystemContext.COMPANYUSER);
		String requestPath = Mvcs.getActionContext().getPath();
		View view = null;
		if (null == companyUser && null == supplierUser) {
			view = new ViewWrapper(new JspView("/common/sessionFailure"), null);
		}
		/*View view = null;
		if (null == obj) {
			if ("/index".equalsIgnoreCase(requestPath)) {
				view = new ServerRedirectView("/user/login");
			} else {
				view = new ViewWrapper(new JspView("jsp/login"), timeOutMsg);
			}
		}*/
		return view;
	}

}